package com.CNMedical.web.controller.system.applet;


import com.CNMedical.common.annotation.Anonymous;
import com.CNMedical.common.core.controller.BaseController;
import com.CNMedical.common.core.domain.R;
import com.CNMedical.system.domain.entity.AppletForum;
import com.CNMedical.system.domain.entity.AppletForumCollect;
import com.CNMedical.system.domain.entity.AppletForumComment;
import com.CNMedical.system.domain.vo.AppletForumCommentVO;
import com.CNMedical.system.service.IAppletForumCollectService;
import com.CNMedical.system.service.IAppletForumCommentService;
import com.CNMedical.system.service.IAppletForumService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "论坛接口")
@Anonymous
@RestController
@RequestMapping("/applet/forum")
public class ForumController extends BaseController {

    @Resource
    private IAppletForumService appletForumService;

    @Resource
    private IAppletForumCommentService appletForumCommentService;

    @Resource
    private IAppletForumCollectService appletForumCollectService;


    /**
     * 获取所有的帖子
     *
     * @date 2023-03-30
     */
    @ApiOperation("获取所有的帖子")
    @GetMapping("/getAllForumPost")
    public R<List<AppletForum>> getAllForumPost() {
        return R.ok(appletForumService.getAllForumPostList());
    }

    /**
     * 通过帖子id获取帖子评论
     *
     * @date 2023-03-30
     */
    @ApiOperation("通过帖子id获取帖子评论")
    @GetMapping("/getForumPostCommentById/{postId}")
    public R<List<AppletForumCommentVO>> getForumPostComment(@PathVariable String postId) {
        return R.ok(appletForumCommentService.getForumPostCommentByPostId(postId));
    }

    /**
     * 发帖
     */
    @ApiOperation("发帖")
    @PostMapping("/addForum")
    public R addForum(@RequestBody AppletForum appletForum)
    {
        return R.ok(appletForumService.insertAppletForum(appletForum));
    }

    /**
     * 评论/回复 帖子
     */
    @ApiOperation("评论/回复帖子")
    @PostMapping("/commentForum")
    public R commentForum(@RequestBody AppletForumComment appletForumComment)
    {
        return R.ok(appletForumCommentService.insertAppletForumComment(appletForumComment));
    }

    /**
     * 删除帖子
     */
    @ApiOperation("删除帖子")
    @DeleteMapping("/deleteForum/{ids}")
    public R remove(@PathVariable Long[] ids)
    {
        return R.ok(appletForumService.deleteAppletForumByIds(ids));
    }

    /**
     * 帖子收藏
     */
    @ApiOperation("帖子收藏")
    @PostMapping("/addForumCollect")
    public R addForumCollect(@RequestBody AppletForumCollect appletForumCollect)
    {
        return R.ok(appletForumCollectService.insertAppletForumCollect(appletForumCollect));
    }

    /**
     * 帖子取消收藏
     */
    @ApiOperation("帖子取消收藏")
    @PostMapping("/cancelForumCollect")
    public R cancelForumCollect(@RequestBody AppletForumCollect appletForumCollect)
    {
        return R.ok(appletForumCollectService.cancelForumCollect(appletForumCollect));
    }

    /**
     * 帖子收藏列表
     */
    @ApiOperation("帖子收藏列表")
    @PostMapping("/getForumCollectListByUserId/{userId}")
    public R getForumCollectListByUserId(@PathVariable String userId)
    {
        return R.ok(appletForumCollectService.getForumCollectListByUserId(userId));
    }

    /**
     * 获取帖子详情
     */
    @ApiOperation("根据帖子id获取帖子详情")
    @PostMapping("/getForumDetailById")
    public R getForumDetailById(@RequestParam String forumId,@RequestParam String userId)
    {
        return R.ok(appletForumService.getForumDetailById(forumId,userId));
    }

    /**
     * 我的帖子
     */
    @ApiOperation("我的帖子")
    @GetMapping("/getMyForumList/{userId}")
    public R getMyForumList(@PathVariable String userId)
    {
        return R.ok(appletForumService.getMyForumList(userId));
    }
}
